<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>
    <script type="text/javascript">
        $(function () {
            $('#ssBrand').searchbox({
                searcher:function(value,name){
                    $("#tableBrand").datagrid("load",{
                        "columnName":name,
                        "columnValue":value,
                    });
                },
                width:300,
                menu:'#mmBrand',
                prompt:'请输入值',
            });

            $("#tableBrand").datagrid({
                url: "${pageContext.request.contextPath}/back/brand/findAll",
                autoRowHeight: true,
                fit:true,
                fitColumns: true,
                toolbar: '#tbBrand',
                columns: [[
                    {field: "checkbox", checkbox: true},
                    {title: "名称", field: "name", width: 100},
                    {title: "介绍", field: "introduction", width: 500},
                    {
                        title: "操作", field: "options", width: 100, formatter: function (value, row, index) {
                            return "<a onclick=showBrand(\""+row.id+"\") class='btnBrand' data-options=\"iconCls:'icon-edit',\">更新</a>";
                        }
                    }
                ]],
                pagination: true,
                checkOnSelect: true,
                selectOnCheck: true,
                pageList:[5,10,20,40,80,100],
                pageSize:5,
                onLoadSuccess: function () {
                    $(".btnBrand").linkbutton();
                }
            });
        });

        //打开添加对话框
        function openAddBrandDialog() {
            $("#addBrandDialog").dialog({
                title:"添加品牌信息",
                iconCls:'icon-save',
                width:600,
                height:400,
                modal:true,
                href:"${pageContext.request.contextPath}/back/brand/add.jsp",
                buttons:[{
                    text:'保存',
                    iconCls:'icon-save',
                    handler:saveBrand,
                },{
                    text:'关闭',
                    iconCls:'icon-cancel',
                    handler:function(){
                        $("#addBrandDialog").dialog("close");
                    }
                }]
            });
        }
        //保存品牌信息
        function saveBrand(){
            $('#saveBrandForm').form({
                url:'${pageContext.request.contextPath}/back/brand/add',
                onSubmit: function(){
                        return $("#saveBrandForm").form("validate");
                },
                success:function(result){
                    result = eval("("+ result +")");
                    $.messager.show({
                        title:'提示信息',
                        msg:result.message,
                        timeout:5000,
                        showType:'slide'
                    });
                    $('#addBrandDialog').dialog("close");
                    $("#tableBrand").datagrid("reload");
                }
            });
            $('#saveBrandForm').submit();
        }
        //更新品牌信息
        function updateBrand(){
            $('#updateBrandForm').form({
                url:'${pageContext.request.contextPath}/back/brand/update',
                onSubmit: function(){
                        return $("#updateBrandForm").form("validate");
                },
                success:function(result){
                    result = eval("("+ result +")");
                    $.messager.show({
                        title:'提示信息',
                        msg:result.message,
                        timeout:5000,
                        showType:'slide'
                    });
                    $('#updateBrandDialog').dialog("close");
                    $("#tableBrand").datagrid("reload");
                }
            });
            $('#updateBrandForm').submit();
        }
        //展示品牌信息
        function showBrand(id){

            $("#updateBrandDialog").dialog({
                title:"更新品牌信息",
                iconCls:'icon-edit',
                width:600,
                height:400,
                modal:true,
                href:"${pageContext.request.contextPath}/back/brand/update.jsp",
                buttons:[{
                    text:'保存',
                    iconCls:'icon-save',
                    handler:updateBrand,
                },{
                    text:'关闭',
                    iconCls:'icon-cancel',
                    handler:function(){
                        $("#updateBrandDialog").dialog("close");
                    }
                }],
                onLoad:function(){
                    $("#updateBrandForm").form('load','${pageContext.request.contextPath}/back/brand/findOne?id='+id);
                }
            });
        }
    </script>
<table id="tableBrand" class="easyui-datagird"></table>

<div id="tbBrand">
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true,onClick:openAddBrandDialog,">添加</a>

    <input id="ssBrand"></input>
    <div id="mmBrand" style="width:120px">
        <div data-options="name:'name',iconCls:'icon-ok'">名称</div>
        <div data-options="name:'introduction',iconCls:'icon-ok'">介绍</div>
    </div>
</div>

<%--添加对话框--%>
<div id="addBrandDialog"></div>
<%--更新对话框--%>
<div id="updateBrandDialog"></div>
